﻿using System.Collections.Generic;

namespace Flickr.Owin.Security.FlickrOAuth
{
    internal class OAuthAccessToken 
    {
        public string Token { get; set; }

        public string TokenSecret { get; set; }

        public string UserId { get; set; }

        public string Username { get; set; }

        public string FullName { get; set; }

        internal static OAuthAccessToken ParseResponse(string response)
        {
            Dictionary<string, string> dictionary = UtilityMethods.StringToDictionary(response);
            var oauthAccessToken = new OAuthAccessToken();
            if (dictionary.ContainsKey("oauth_token"))
                oauthAccessToken.Token = dictionary["oauth_token"];
            if (dictionary.ContainsKey("oauth_token_secret"))
                oauthAccessToken.TokenSecret = dictionary["oauth_token_secret"];
            if (dictionary.ContainsKey("user_nsid"))
                oauthAccessToken.UserId = dictionary["user_nsid"];
            if (dictionary.ContainsKey("fullname"))
                oauthAccessToken.FullName = dictionary["fullname"];
            if (dictionary.ContainsKey("username"))
                oauthAccessToken.Username = dictionary["username"];
            return oauthAccessToken;
        }
    }
}
